#include <encrypt.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
#include <string.h>
#include <sys/time.h>

#define LOOP 1000
int main(int argc, char** argv)
{
	if(argc != 2)
		return 0;

	printf("origin: %s\n", argv[1]);

	srand(time(NULL));
	int32_t key = rand();
	char enc[1024];
	size_t enc_len = sizeof(enc);

	struct timeval tv;
	gettimeofday(&tv, NULL);
	printf("%d.%06d: start encrypt\n", tv.tv_sec, tv.tv_usec);
	int index = 0;
	while(index++ < LOOP)
	{
		enc_len = sizeof(enc);
		int ret = base_encrypt(argv[1], strlen(argv[1]), key, enc, &enc_len);
		assert(0 == ret);	
	}
	gettimeofday(&tv, NULL);
	printf("%d.%06d: complete encrypt\n\n", tv.tv_sec, tv.tv_usec);
	
	char des[1024];
	size_t des_len = sizeof(des);
	gettimeofday(&tv, NULL);
	printf("%d.%06d: start descrypt\n", tv.tv_sec, tv.tv_usec);
	index = 0;
	while(index++ < LOOP)
	{
		des_len = sizeof(des);
		int ret = base_descrypt(enc, enc_len, key, des, &des_len);
		assert(0 == ret);	
	}
	gettimeofday(&tv, NULL);
	printf("%d.%06d: complete descrypt\n", tv.tv_sec, tv.tv_usec);
	
	des[des_len] = 0;
	printf("after descrypt: %s\n", des);
	return 0;
}

